<template>
  <div>
    <el-table :data="items">
        <!-- <el-table-column prop="date" label="日期" width="140">
        </el-table-column> -->
        <el-table-column prop="_id" label="ID" width="230">
        </el-table-column>
        <el-table-column prop="name" label="班次名称">
        </el-table-column>
        <el-table-column prop="start_position" label="起点">
        </el-table-column>
        <el-table-column prop="end_position" label="终点">
        </el-table-column>
        <el-table-column  prop="start_date" label="出发时间">
        </el-table-column>
        <el-table-column  prop="end_date" label="到达时间">
        </el-table-column>
         <el-table-column prop="left" label="剩余票数">
        </el-table-column>
        <el-table-column prop="money" label="价格">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="180">
      <template slot-scope="scope">
        <el-button type="text" size="small" @click="$router.push(`/trans/edit/${scope.row._id}`)">编辑</el-button>
        <el-button type="text" size="small" @click="remove(scope.row)">删除</el-button>
      </template>
    </el-table-column>
      </el-table>
  </div>
</template>
<script>
export default {
  data(){
    return{
      items:[]
    }
  },
  methods:{
    async fetch(){
      const res =await this.$http.get('rest/flights')
      this.items=res.data
      this.items.forEach((time,index)=>{
        time.start_date = this.$moment(time.start_date).format('YYYY-MM-DD HH:mm:ss')
        time.end_date = this.$moment(time.end_date).format('YYYY-MM-DD HH:mm:ss')
        console.log(this.time_show)
      })
      console.log(this.items)
    },
    async remove(row){
      this.$confirm(`此操作将永久删除该航航班?"${row.name}", 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(async () => {
          const res =await this.$http.delete(`rest/flights/${row._id}`)
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.fetch()
        })          
      }
  },
  created(){
    this.fetch()
  }
};
</script>

